﻿using Newtonsoft.Json;
using Omabar.BLL;
using Omabar.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace Omabar.CMS.Handler
{
    /// <summary>
    /// SliderDelete 的摘要说明
    /// </summary>
    public class SliderDelete : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            RESP_Info info = new RESP_Info();

            try
            {
                context.Response.ContentType = "text/plain";
                bool batch = string.IsNullOrEmpty(context.Request["batch"]) ? false : bool.Parse(context.Request["batch"]);
                Slider_BLL bll = new Slider_BLL();
                if (batch)
                {
                    string[] ids = context.Request["ids[]"].Split(',');

                    foreach (string id in ids)
                    {
                        info = bll.Delete(new SLIDER() { SLIDER_ID = id });
                    }
                }
                else
                {
                    string id = context.Request["id"];
                    info = bll.Delete(new SLIDER() { SLIDER_ID = id });
                }
            }
            catch (Exception ex)
            {
                info.Success = false;
                info.Title = "错误";
                info.Tip = "幻灯片删除失败";
                info.Url = "SliderList.aspx";
            }

            context.Response.Write(JsonConvert.SerializeObject(info));
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}